package com.talkingdata.hadoop.guard.mapper;


import com.talkingdata.hadoop.guard.bean.SchedulerState;
import org.apache.ibatis.annotations.*;

@Mapper
public interface SchedulerMapper {
    @Insert("insert into scheduler_state (cluster_id,queue_name,str_memory,memory," +
            "v_cores,queues_max_resources,queues_used_resources," +
            "queues_used_resources_percent,scheduler_type,timestamp) values (" +
            "#{clusterId},#{queueName},#{strMemory},#{memory},#{vCores},#{queuesmaxResources}," +
            "#{queuesUsedResources},#{queuesUsedResourcesPercent},#{schedulerType},#{timestamp})")
    int insertScheduler(SchedulerState schedulerState);

    @Select("select cluster_id,queue_name,str_memory,memory," +
            "v_cores,queues_max_resources,queues_used_resources," +
            "queues_used_resources_percent,scheduler_type,timestamp " +
            "from scheduler_state where cluster_id = #{cluster_id} " +
            "and queue_name = 'root' order by id DESC limit 1 ")
    @Results({
            @Result(property = "clusterId",column = "cluster_id"),
            @Result(property = "queueName",column = "queue_name"),
            @Result(property = "strMemory",column = "str_memory"),
            @Result(property = "vCores",column = "v_cores"),
            @Result(property = "queuesmaxResources",column = "queuesmax_resources"),
            @Result(property = "queuesUsedResources",column = "queues_used_resources"),
            @Result(property = "queuesUsedResourcesPercent",column = "queues_used_resources_percent"),
            @Result(property = "schedulerType",column = "scheduler_type")
    })
    SchedulerState selectSchedulerStateByClusterId(String cluster_id);
}
